﻿using LJX.SmartPark.Domain.SafeManage;
using LJX.SmartPark.Domain.Student;
using LJX.SmartPark.Domain.SysManage;
using LJX.SmartPark.EntityFramework;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.SafeManage
{
    public class HouseInfoService : IHouseInfoService
    {
        private readonly IRepository<HouseInfo> _studentService;


        public HouseInfoService(IRepository<HouseInfo> studentService)
        {
            _studentService = studentService;
        }

        public object GetHouseInfoSelect(int id = 0)
        {
            var students = _studentService.GetListQuery().Where(x => x.PId == id).ToList();
            if (students.Count == 0)
            {
                return null;
            }
            var list = students.Select(a => new
            {
                value = a.Id,
                label = a.Site,
                children = GetHouseInfoSelect(a.Id)
            }).ToList();
            return list;
        }

        public object GrtTreeHouseInfo(int id = 0)
        {
            var students = _studentService.GetListQuery().Where(x => x.PId == id).ToList();
            if (students.Count == 0)
            {
                return null;
            }
            var list = students.Select(a => new
            {
                id = a.Id,
                label = a.Site,
                children = GrtTreeHouseInfo(a.Id)
            }).ToList();

            return list;
        }
    }
}
